<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.css" rel="stylesheet">
    <link th:href="@{/css/login.css}" rel="stylesheet" />
    <link href="https://at.alicdn.com/t/font_2866320_i02r3rlrf7l.css" rel="stylesheet" type="text/css" />
    <title>登录-成信大抽奖系统</title>
</head>

<body>
    <!-- 别忘了更新css -->
    <div class="container">
        <div class="innerBox">
            <div class="titleBox">
                <h4>抽奖系统登录</h4>
            </div>
            <div class="loginBox">
                <div class="left">
                   <img th:src="@{/images/zl.jpg}" class="login_img"/>
                </div>
                <div class="right">
                    <img th:src="@{/images/logo_03.png}" class="cuit-logo"/>
                    <div class="w-75">
                    <div class="input-group mb-3">
                        <span class="input-group-text iconfont icon-yonghudenglu"></span>
                        <input type="text" class="form-control" placeholder="用户名" id="username">
                    </div>
                    <div class="input-group mb-3">
                        <span class="input-group-text iconfont icon-yuechi"></span>
                        <input type="password" class="form-control" placeholder="登录密码" id="password">
                    </div>
                    <div class="text-center w-100 btns">
                        <div class="my-btn" onclick="fogetPwd()">忘记密码</div>
                        <div class="my-btn" onclick="login()">登录系统</div>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.bundle.min.js"></script>
    <script>

        function login(){
            let usr = $('#username').val();
            let pwd = $('#password').val();
            $.ajax({
                url: '/user/doLogin',
                method: 'POST',
                data: {
                    "username": usr,
                    "password": pwd
                },
                success(data){
                    if(data === true){
                        sessionStorage.setItem("userInfo", usr);
                        location.href='/';
                    } else {
                        alert("登录失败，请联系管理员");
                    }
                }
            })
        }
        function forgetPwd(){
            alert("请联系管理员");
        }
    </script>
</body>

</html>
